home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 112 / EnigmaAmiga112CD.iso / dalla rivista / awnpipe / awnp / awnp-docs / tutorials / tutorial5.rx < prev    next >
Text File  |  2000-05-12  |  13KB  |  469 lines

  1. /*Tutorial 5 for AWNPipe*/
  2.  
  3. /* uniconify and front of old window it tutorial 5 is already running*/
  4. if show('P','TUTORIAL5') then do
  5.   address TUTORIAL5 'front'
  6.   exit
  7. end
  8.  
  9. delaybub=0
  10. call setdefaults()
  11. /* override defaults and get window size and position */
  12. call tooltypes()
  13. /*open GUI*/
  14. call buildgui()
  15. if (tticonify) then call iconify(1)
  16. /*main loop*/
  17. do while ~eof(ca)
  18.   call topipe('tick 50')
  19.   in= readln(ca)
  20.   parse var in in1 in2 in3 in4 in5 .
  21.   /*handle help display delay*/
  22.   if delaybub>0 then do
  23.     delaybub=delaybub-1
  24.     /* if we reach zero display the help bubble*/
  25.     if delaybub=0 then do
  26.       bubleon=newbub
  27.       call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
  28.     end
  29.   end
  30.  
  31.   if (in1='help' & helpon~=0 ) then call bubble(in2)
  32.  
  33.   /*close help bubble if active state of window changes*/
  34.   if in1='active' then call bubble(0)
  35.   if in1='gadget' then call gadget()
  36.   if in1='menu' then call menu()
  37.   if in1='close' then call windowclosed()
  38.   if in1='iconify' then call iconify(in2)
  39.   if in1='app' then call app()
  40.   if in1='arexx' then call rxhst()
  41.   if in1='cx' then call commodity()
  42.  
  43. end
  44. /*end of main loop*/
  45.  
  46. exit
  47.  
  48. gadget:
  49. if in2=agegad then age=in3
  50. if in2=sexgad then sex=in3
  51. if in2=knogad then knowledge=in3
  52. if in2=basgad then basic=in3
  53. if in2=aregad then arexx=in3
  54. if in2=cgad then c=in3
  55. if in2=asmgad then asm=in3
  56. /* the return from a string gadget is parsed differently since it can be more
  57. then 1 word. */
  58. if in2=namegad then do
  59.   parse var in . . in3
  60.   /*strip it since arexx parsing adds the leading space to the last string
  61.   assignment*/
  62.   name=strip(in3)
  63.   if name='' then call topipe('id 'savegad' dis 1 ref')
  64.   else call topipe('id 'savegad' dis 0 ref')
  65. end
  66.  
  67. if in2=dongad then do
  68.   showtx(0, 'Normal exit *nname' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  69.   exit
  70. end
  71.  
  72. if in2=resgad then call resetform()
  73. if in2=savegad then call saveform()
  74. if in2=loadgad then call loadform()
  75.  
  76. if in2=cangad then do
  77.   showtx(300,'user canceled')
  78.   exit
  79. end
  80.  
  81. return
  82.  
  83. windowclosed:
  84. showtx(300,'User aborted with CTRL BackSlash or closed window.')
  85. exit
  86. return
  87.  
  88. menu:
  89. if in2=0 then do
  90.   if in3=0 then do
  91.     if in4=0 then call settooltypes(1)
  92.     if in4=1 then call settooltypes(0)
  93.   end
  94.   if in3=1 then do
  95.     helpon=in5
  96.     if helpon=0 then call bubble(0)
  97.   end
  98.   if in3=3 then showtx(500,' Tutorial 4 for AWNP *n  by William Parker')
  99. end
  100.  
  101.  
  102. if in2=1 then do
  103.   if in3=0 then do
  104.     showtx(0, 'name' name '*nage' age '*nsex' sex '*nknowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  105.   end
  106.   if in3=1 then do
  107.     if in4=0 then showtx(0, 'name' name '*nage' age '*nsex' sex)
  108.     if in4=1 then showtx(0, 'knowledge' knowledge '*nbasic' basic 'arexx' arexx 'c' c 'asm' asm)
  109.   end
  110. end
  111. return
  112.  
  113.  
  114. setdefaults:
  115. name=''
  116. age=30
  117. sex=0
  118. knowledge=0
  119. basic=0
  120. c=0
  121. asm=0
  122. arexx=0
  123. tticonify=0
  124. helpon=1
  125. return
  126.  
  127. buildgui:
  128.  
  129. /* Open pipe 'tut2' with GUI creation option '/xc' */
  130. call open(ca,"awnpipe:tut5/xc")
  131.  
  132. /* define the window */
  133.  
  134. /* The first line oF every GUI is the window definition. The window is titled
  135. "Tutorial 2" and its elements will be laid out verticaly (v). It has a
  136. closegadget (cg) , depthgadget (dg) , and dragbar (db). It will have spaces
  137. inbetween its gadgets (si). It will open on the topleft (tl) of the screen
  138. becoming active (a) when opened. The window can be icoified (ig) and modified
  139. (m). It is an app window (app) . It can be sized (SG) but not verticaly (fh)*/
  140.  
  141. call topipe('"Tutorial 5" v cg dg db si a help state ig sg fh m app ii "tutorial4.rx" 'ttwindow)
  142.  
  143. /* define the gadgets*/
  144.  
  145. call topipe(' layout b 0 v')
  146.  
  147. /* Labels are used to tell the user what information to enter in each gadget.
  148. These labels are unatached (ua) when they are defined so don't go directly
  149. into the GUI. Instead they are attached to the following gadget by the
  150. childlabel (chl) keyword. */
  151.  
  152. call topipe(' label  gt "Name: " ua')
  153. namegad=topipe('string lj chl gt "'name'"')
  154. help.namegad='Enter a name here. This feild must be valid*n before you can save the information.'
  155.  
  156. call topipe(' label gt "Age: " ua')
  157. agegad=topipe('integer chl minn 5 maxn 115 arrows defn 'age'  weiw 0')
  158. help.agegad='Enter an age between 5 and 115'
  159.  
  160. call topipe(' label gt "Sex: " ua')
  161. sexgad=topipe('radiobutton rl "Male|Female" chl s 'sex)
  162. help.sexgad='You may only choose one sex.'
  163.  
  164. call topipe(' label gt "Knowledge: " ua')
  165. knogad=topipe('chooser pu cl "Novice|Average|Good|Expert" chl s 'knowledge)
  166. help.knogad='Enter your programming knowledge level.'
  167.  
  168. call topipe(' label gt "Language(s): " ua')
  169.  
  170. call topipe(' layout b 0 chl')
  171. basgad=topipe('checkbox gt "Basic " chl')
  172. help.basgad='Select if you program in Basic.'
  173.  
  174. aregad=topipe('checkbox gt "Arexx " chl')
  175. help.aregad='Select if you program in Arexx.'
  176.  
  177. cgad=topipe('checkbox gt "C " chl')
  178. help.cgad='Select if you program in C.'
  179.  
  180. asmgad=topipe('checkbox gt "ASM " chl')
  181. call topipe(' le')
  182. help.asmgad='Select if you program in Assembler.'
  183.  
  184. call topipe(' le')
  185.  
  186. call topipe(' layout si so')
  187. savegad= topipe('button gt "Save" dis 1')
  188. help.savegad='Save data to a file.*n(You must enter a name first)'
  189.  
  190. loadgad= topipe('button gt "Load" ')
  191. help.loadgad='Read a data file.'
  192.  
  193. resgad= topipe('button gt "Reset Form" ')
  194. help.resgad='Reset the form to defaults.'
  195.  
  196. dongad= topipe('button gt "Done" c')
  197. help.dongad='Display data and quit the demo.'
  198.  
  199. cangad= topipe('button gt "Cancel" c')
  200. help.cangad='Quit the demo without displaying the data.'
  201.  
  202. call topipe(' le')
  203.  
  204.  
  205. men0=topipe(' menu gt "Project|Window|$@SSnapshot|$@UUnSnapshot|^&Bubble Help|-|About"')
  206. men1=topipe(' menu gt "Data|@AShow all data|Show part|$@PPersonal|$@SSkill"')
  207. call topipe(' arexx gt "TUTORIAL5|age|sex|knowledge|front|quit"')
  208.  
  209. getfilegad=topipe('getfile gt "Select Information File" fn "t:" ua pat "#?.tut3"')
  210. call topipe('commodity cxname Demo5 cxtitle="AWNPipe demo 5" cxdesc="Disable Enable ignored..." cxhotkey="ctrl alt 5"')
  211. /*open the GUI window*/
  212. call topipe("open")
  213. call topipe('id 'savegad' dis 1 ref')
  214. if (~helpon) then call topipe('id 'men0' tar 3 s 0 ')
  215. return
  216.  
  217.  
  218. topipe:
  219. /* this routine does error checking on lines written to pipe.*/
  220.  
  221. /*get line to output*/
  222. parse arg out
  223.  
  224. /* write to the pipe*/
  225. call writeln(ca,out)
  226.  
  227. /*get responce and parse it.*/
  228. res=readln(ca)
  229. parse var res res1 res2 .
  230.  
  231. /* if all is ok return the second part of the responce (usualy the GID)*/
  232. if res1='ok' then return(res2)
  233.  
  234. /* something went wrong, we notify the user then exit */
  235. /*show problem line and responce (reponce may be just a blank line)*/
  236. say 'error from: 'out
  237. say '  responce: ' res
  238. exit
  239.  
  240. resetform:
  241. call topipe('id 'agegad' defn 30 ref')
  242. call topipe('id 'sexgad' s 0 ref')
  243. call topipe('id 'knogad' s 0 ref ')
  244. call topipe('id 'basgad' s 0 ref')
  245. call topipe('id 'aregad' s 0 ref')
  246. call topipe('id 'cgad' s 0 ref ')
  247. call topipe('id 'asmgad' s 0 ref')
  248. call topipe('id 'namegad' gt "" ref')
  249. topipe('id 'savegad' dis 1 ref')
  250. call setdefaults()
  251. return
  252.  
  253. saveform:
  254. call open(form,'t:'name'.tut3','W')
  255. call writech(form,age sex knowledge basic arexx c asm name)
  256. call close(form)
  257. return
  258.  
  259. loadform:
  260. call writeln(ca,'id 'getfilegad' fn "t:" s 1')
  261. res=readln(ca);
  262. parse var res res1 '"' filename '"'
  263. loadapp:
  264. if res1=0 then return
  265. call open(form,filename,'R')
  266. formin=readch(form,1000)
  267. parse var formin age sex knowledge basic arexx c asm name
  268. name=substr(name,2)
  269. call close(form)
  270. /*uniconify in case its needed*/
  271. update:
  272.  
  273. call topipe('id 'agegad' defn 'age' ref')
  274. call topipe('id 'sexgad' s 'sex' ref')
  275. call topipe('id 'knogad' s 'knowledge' ref ')
  276. call topipe('id 'basgad' s 'basic' ref')
  277. call topipe('id 'aregad' s 'arexx' ref')
  278. call topipe('id 'cgad' s 'c' ref ')
  279. call topipe('id 'asmgad' s 'asm' ref')
  280. call topipe('id 'namegad' gt "'name'" ref')
  281. if name='' then call topipe('id 'savegad' dis 1 ref')
  282. else call topipe('id 'savegad' dis 0 ref')
  283. return
  284.  
  285. app:
  286. parse var in . in2
  287. filename=strip(in2)
  288. if (right(filename,5)='.tut3') then do
  289.   res1=1
  290.   call loadapp()
  291. end
  292. return
  293.  
  294. /* send a modify command to iconify/uniconify window and remember the current
  295. state of the window*/
  296. iconify:
  297. iconified=arg(1)
  298. if iconified=1 then call topipe('id 0 s 32')
  299. else  call topipe('id 0 s 64')
  300. call bubble(0)
  301. return(0)
  302.  
  303. showtx:
  304. call open(ptx,'awnpipe:tut3txt/xc')
  305. call writeln(ptx,'db dg "Tutorial 4" q cg cm m a so si ')
  306. call writeln(ptx,'label lj gt "'arg(2)'"')
  307. call writeln(ptx,'open')
  308. if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
  309. else call writeln(ptx,'m')
  310. call close(ptx)
  311. return(0)
  312.  
  313. bubble:
  314. /* get help gadget number*/
  315. newbub=arg(1)
  316. if newbub=-1 then newbub=0
  317. /* return if it has not changed*/
  318. if (bubbleon=newbub) then return()
  319. /* close old bubble if we have one*/
  320. if bubbleon~=0 then call  topipe('bubble')
  321. /* if its not a valid gadget kill count down to display*/
  322. if newbub=0 then delaybub=0
  323. /*else remeber mouse position and start new countdown*/
  324. else do
  325.   bubx=in3
  326.   buby=in4
  327.   delaybub=3
  328. end
  329. return
  330.  
  331. rxhst:
  332.  
  333. /*read the external command from the pipe, it is in3 characters long*/
  334. rxcmd=readch(ca,in3)
  335. /* return an error if unrecognized command */
  336. if in2>4 then call topipe("rc 10")
  337. /*front*/
  338. if in2=3 then do
  339.   call topipe('rc 0 result "Window brought to front"')
  340.   call topipe('id 0 s 66')
  341. end
  342. /*quit*/
  343. if in2=4 then do
  344.   call topipe('rc 0 result "tutrial 5 exiting"')
  345.   exit
  346. end
  347. /* other*/
  348. parse var rxcmd rx1 rx2 .
  349. /* if no new value set return current value in result*/
  350. if rx2='' then do
  351.   if in2=0 then call topipe('rc 0 result "'age'"')
  352.   if in2=1 then call topipe('rc 0 result "'sex'"')
  353.   if in2=2 then call topipe('rc 0 result "'knowledge'"')
  354. end
  355. /*new value given so put it where it belongs*/
  356. else do
  357.   if in2=0 then age=rx2
  358.   if in2=1 then sex=rx2
  359.   if in2=2 then knowledge=rx2
  360.   call topipe('rc 0')
  361.   call update()
  362. end
  363. return
  364.  
  365. commodity:
  366. /* self explanitory */
  367. if in2='show' then call iconify(0)
  368. if in2='hide' then call iconify(1)
  369. if in2='kill' then exit
  370. if in2='hotkey' then call iconify(0)
  371. return
  372.  
  373. tooltypes:
  374. /* find the path and name to the script */
  375. parse source . . . resolved .
  376. /* open a pipe to query the tooltypes */
  377. if open(ttfh,'awnpipe:tt/xt'resolved) then do
  378.  
  379.   /* check the age tool type */
  380.   call writeln(ttfh,'age')
  381.   /* parse the responce to our query */
  382.   parse value readln(ttfh) with tt1 tt2
  383.   /* if the tooltype was found we get 'ok VALUE' back from pipe */
  384.   /* we check for 'ok' and a valid value*/
  385.   if tt1='ok' & datatype(tt2,'N') then  age=tt2
  386.  
  387.   /* check the sex tooltype */
  388.   call writeln(ttfh,'sex')
  389.   parse value readln(ttfh) with tt1 tt2
  390.   if tt1='ok' & datatype(tt2,'N') then sex=tt2
  391.  
  392.   /* check the knowledge tooltype*/
  393.   call writeln(ttfh,'knowledge')
  394.   parse value readln(ttfh) with tt1 tt2
  395.   if tt1='ok' & datatype(tt2,'N') then knowledge=tt2
  396.  
  397.   /* check the name tooltype*/
  398.   call writeln(ttfh,'name')
  399.   parse value readln(ttfh) with tt1 tt2
  400.   if tt1='ok' then name=strip(tt2)
  401.  
  402.   /* check the bubble tool type */
  403.   call writeln(ttfh,'bubble')
  404.   parse upper value readln(ttfh) with tt1 tt2
  405.   /* check for the 'ok' then for 'on' 'ON' or '1'*/
  406. if tt1='OK' then do
  407.   if (tt2='ON' | tt2=1) then helpon=1
  408.   else helpon=0
  409. end
  410.   /* check the iconify tool type */
  411.   call writeln(ttfh,'iconify')
  412.   parse value readln(ttfh) with tt1 tt2
  413.   /* iconify has no value so just check for the 'ok' */
  414.   if tt1='ok' then tticonify=1
  415.  
  416.   /* check the window tool type (height is ignored for this GUI !)*/
  417.   call writeln(ttfh,'window')
  418.   parse value readln(ttfh) with tt1 wl wt ww .
  419.   /* check window definition validity AND the 'ok' */
  420.   if (tt1='ok' & datatype(wt,N) &datatype(wl,N) &datatype(ww,N) )
  421.  then ttwindow='left' wl 'top' wt 'width' ww 'height' 1
  422.   /*if no tool type we just open top left */
  423. else ttwindow='tl'
  424.  
  425.   call close(ttfh)
  426. end
  427. return
  428.  
  429.  
  430. settooltypes:
  431. /* find the path and name to the script */
  432. parse source . . . resolved .
  433. /* open a pipe to read icon information */
  434. if open(ttfh,'awnpipe:tt/xi'resolved) then do
  435.   /*get the first 3 lines they are always present*/
  436.   icondata=readln(ttfh)
  437.   /* a null first line means we have no icon*/
  438.   if icondata~='' then do
  439.     icondata=icondata'0a'x||readln(ttfh)
  440.     icondata=icondata'0a'x||readln(ttfh)
  441.     /* read all tooltypes removing window and bubble tooltype*/
  442.     do while ~eof(ttfh)
  443.       tt1=readln(ttfh)
  444. select
  445. when upper(left(tt1,6))='WINDOW'  then nop
  446. when upper(left(tt1,6))='BUBBLE'  then nop
  447. otherwise icondata=icondata'0a'x||tt1
  448. end
  449.     end
  450.   end
  451.   /* no icon so set default */
  452.   else icondata='4 -2147483648 -2147483648 10000'||'0a'x||'rx'||'0a0a'x
  453.   call close(ttfh)
  454.   /* add window info if arg1=1, if arg1=0 then don't (unsnapshot)*/
  455. if arg(1)=1 then do
  456.   call writeln(ca,'id 0 read')
  457.   windowr=readln(ca)
  458. icondata=icondata'window='windowr'0a'x
  459. icondata=icondata'bubble='helpon'0a'x
  460. end
  461.   /*fh to write the new icon definition*/
  462.   if open(ttfh,'awnpipe:tt/xs'resolved) then do
  463.     /* write old info plus new window definition */
  464.     call writech(ttfh,icondata)
  465.     call close(ttfh)
  466.   end
  467. end
  468. return
  469.